package edu.mit.media.fv.components
{
	import flash.display.Sprite;

	public class FVDropList extends Sprite
	{
		private var items:Array = new Array();
		private var isOpen:Boolean = false;
		private var _selectedIndex:int = -1;
		
		public function FVDropList()
		{
			super();
		}
		
		//array of objects
		public function setItems(items:Array):void{
			for(var i:int = 0; i<items.length; i++){
				var item:FVCell = new FVCell(
					0,
					this._height*(i+1),
					this._width,
					this._height,
					i,
					items[i].toString())
				//item.addEventListener(MouseEvent.CLICK, handleSelected);
				this.items.push(item);
			}
			if (items.length > 0){
				this._field.text = items[0].toString();
				this._selectedIndex = 0;
			}			
		}
		public function open():void{
			for(var i:int = 0; i<items.length; i++){
				var item:TextField = items[i];
				this.addChild(item);
			}
			this.isOpen = true;
		}
		public function close():void{
			for(var i:int = 0; i<items.length; i++){
				var item:TextField = items[i];
				this.removeChild(item);
			}
			
			this.isOpen = false;
		}
		public function get selectedIndex():int{
			return this._selectedIndex;
		}
		public function set selectedIndex(index:int):void{
			this._field.text = FVCell(this.items[index]).text;
			this._selectedIndex = index;
		}
		
		
	}
}